
#ifndef TP_WND_MANAGER_H
#define TP_WND_MANAGER_H

#include "tp_widget.h"

TP_DECL_BEGIN

struct _TpWndManager;
typedef struct _TpWndManager TpWndManager;

/* 添加一个窗口，是在新建一个应用窗口时被调用 */
typedef TpRet (*TpWndManagerAdd)(TpWndManager* thiz, TpWidget* window);

/* 在当前应用窗口被关闭销毁时被调用 */
typedef TpRet (*TpWndManagerRemove)(TpWndManager* thiz, TpWidget* window);

/*
	响应各种事件，主要包括键盘鼠标事件、自定义的窗口相关的全局事件。
	处理方式即是将事件分发到当前窗口和注册挂钩的窗口
*/
typedef TpRet (*TpWndManagerOnEvent)(TpWndManager* thiz, TpEvent* event);

/* 结束时用于销毁所创建的管理器 */
typedef void (*TpWndManagerDestroy)(TpWndManager* thiz);

struct _TpWndManager 
{
	TpWndManagerAdd add;
	TpWndManagerRemove remove;
	TpWndManagerOnEvent on_event;
	TpWndManagerDestroy destroy;

	char priv[1];
};

static inline TpRet tp_wnd_manager_add(TpWndManager* thiz, TpWidget* window)
{
	if (NULL == thiz || NULL == window) return TP_RET_BADARGS;

	return thiz->add(thiz, window);
}

static inline TpRet tp_wnd_manager_remove(TpWndManager* thiz, TpWidget* window)
{
	if (NULL == thiz || NULL == window) return TP_RET_BADARGS;

	return thiz->remove(thiz, window);
}

static inline TpRet tp_wnd_manager_on_event(TpWndManager* thiz, TpEvent* event)
{
	if (NULL == thiz || NULL == event) return TP_RET_BADARGS;

	return thiz->on_event(thiz, event);
}

static inline void tp_wnd_manager_destroy(TpWndManager* thiz)
{
	if (NULL != thiz)
	{
		thiz->destroy(thiz);
	}

	return;
}

void tp_wnd_manager_init(void);

TP_DECL_END

#endif /*TP_WND_MANAGER_H*/